Class GameBoard

java.lang.Object
cpsc2150.extendedConnectX.models.AbsGameBoard
cpsc2150.extendedConnectX.models.GameBoard
All Implemented Interfaces:
IGameBoard

public class GameBoard extends AbsGameBoard implements IGameBoard
Class that represents an entire game board for the ExtendedConnectX game using an array.

This class includes methods to place tokens, check token locations, and determine whether or not the game has been won or is over.

Invariant:
(board[][] = ' ' OR board[][] = [ a player token ]) AND [ there are no gaps between non-space tokens ] AND MIN_ROWS <= numRows < MAX_ROWS AND MIN_COLUMNS <= numColumns < MAX_COLUMNS MIN_NUM_TO_WIN <= numToWin <= MAX_NUM_TO_WIN
  • Constructor Details

    • GameBoard

      public GameBoard(int rows, int columns, int win)
      Constructor for GameBoard that takes parameters for the number of rows, the number of columns, and the number needed to win, and initializes all indexes of board to ' '.
      Parameters:
      rows - Number of rows
      columns - Number of columns
      win - Number needed to win
      Pre:
      MIN_ROWS <= rows < MAX_ROWS AND MIN_COLUMNS <= columns < MAX_COLUMNS AND MIN_NUM_TO_WIN <= win <= MAX_NUM_TO_WIN AND win <= rows AND win <= columns
      Post:
      board[][] = ' ' AND numRows = rows AND numColumns = columns AND numToWin = win AND [ size of board[] ] = numRows AND [ size of board[][] ] = numColumns
  • Method Details

    • placeToken

      public void placeToken(char p, int c)
      Description copied from interface: IGameBoard
      Function that places the character p in column c. The token will be placed in the lowest available row in column c.
      Specified by:
      placeToken in interface IGameBoard
      Parameters:
      p - Character to be placed (representing player token)
      c - Column to place token in
    • whatsAtPos

      public char whatsAtPos(BoardPosition pos)
      Description copied from interface: IGameBoard
      Function that returns what is in the GameBoard at position pos. If no marker is there, it returns a blank space char.
      Specified by:
      whatsAtPos in interface IGameBoard
      Parameters:
      pos - BoardPosition pair of row and column
      Returns:
      Character representing player token or space
    • getNumRows

      public int getNumRows()
      Description copied from interface: IGameBoard
      Returns the number of rows in the GameBoard.
      Specified by:
      getNumRows in interface IGameBoard
      Returns:
      The number of rows
    • getNumColumns

      public int getNumColumns()
      Description copied from interface: IGameBoard
      Returns the number of columns in the GameBoard.
      Specified by:
      getNumColumns in interface IGameBoard
      Returns:
      The number of columns
    • getNumToWin

      public int getNumToWin()
      Description copied from interface: IGameBoard
      Returns the number of tokens in a row needed to win the game.
      Specified by:
      getNumToWin in interface IGameBoard
      Returns:
      The number of tokens